#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <network_manager.h>

static PT_networkOpr networkOprHead;

int registerNetWork(PT_networkOpr g_pNetworkOpr)
{
	PT_networkOpr me = networkOprHead;

	if(g_pNetworkOpr ==NULL)
		return -1;

	if(networkOprHead ==NULL)
	{
		networkOprHead = g_pNetworkOpr;
	}
	else
	{
		while(me->next !=NULL)
		{
			me = me->next;
		}
		me->next = g_pNetworkOpr;
	}

	return 0;
}

int initNetWork(void)
{
	int ret;

	ret = clientNetWorkInit();
	if(ret<0)
	{
		fprintf(stderr,"clientNetWorkInit error\n");
		return -1;
	}

	ret = serverNetWorkInit();
	if(ret<0)
	{
		fprintf(stderr,"serverNetWorkInit error\n");
		return -1;
	}

	return 0;
}

void showNetWork(void)
{
	int i=0;
	PT_networkOpr me = networkOprHead;

	while(me!=NULL)
	{
		fprintf(stdout,"%02d %s\n",i++,me->name);
		me = me->next;
	}
}

PT_networkOpr selectNetWork(char *name)
{
	PT_networkOpr me = networkOprHead;

	while(me!=NULL)
	{
		if(strcmp(me->name,name) ==0)
			return me;
		me = me->next;
	}
	
	return NULL;
}

